<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use kartik\editable\Editable;

$this->title = Yii::t('app', 'Rooms');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="room-index">

    <h2 class="page-header"><?= Html::encode($this->title) ?>
        <p class="pull-right">
        <?= Html::a(Yii::t('app', 'Create Room'), ['create', 'cruise_id'=>$cruise_id], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Index'), ['cruise/index'], ['class' => 'btn btn-danger']) ?>
        </p>
    </h2>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

<?PHP Pjax::begin(['id'=>'cruise-room','timeout'=>3000,'linkSelector'=>'#cruise-room a[data-sort],#cruise-room a[data-page]']);?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],
            'cruise.name',
            'name',
            'code',
            [
                'attribute' => 'type',
                'filter' =>  Yii::$app->params['room_type'],
                'value' => function ($model) {
                    return Yii::$app->params['room_type'][$model->type];
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'windows',
                'filter' =>  Yii::$app->params['windows'],
                'value' => function ($model) {
                    return Yii::$app->params['windows'][$model->windows];
                },
                'format' => 'raw',
            ],
            //[
            //    'attribute' => 'balcony',
            //    'filter' =>  Yii::$app->params['balcony'],
            //    'value' => function ($model) {
            //        return Yii::$app->params['balcony'][$model->balcony];
            //    },
            //    'format' => 'raw',
            //],
            'area',
            'balcony_area',
            'num',
            [
                'attribute' => 'min',
                'label' => '最少',
                'value' => function ($model) {
                    return $model->min;
                },
            ],
            [
                'attribute' => 'ceil',
                //'filter' =>  Yii::$app->params['windows'],
                'value' => function ($model) {
                    $ceil  = json_decode($model->ceil);
                    return !empty($ceil) ? implode(',', $ceil) : '(未设置)';
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'status',
                'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
                    return Yii::$app->params['status'][$model->status];
                },
                'format' => 'raw',
            ],
            [
                'attribute' => 'sort',
                //'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
					$str = kartik\editable\Editable::widget([
    					    'name' => 'sort',
							'asPopover' => false,
							'value' => $model->sort,
    					    'header' => '舱房顺序',
    					    'size'=>'md',
    					    'formOptions' => ['action'=>'/cruise/room/sort?id='.$model->id, 'method'=>'get'],
    					    //'options' => ['class'=>'', 'value'=> $model->sort],
    					]);

                    return $str;
                },
                'format' => 'raw',
            ],
            [
                'label'=>'图片',
                'format'=>'raw',
                'value' => function($model){
                    $r =  urlencode(\yii::$app->request->getUrl());
                    $url = sprintf("/cruise/room/image?id=%d", $model->id);
                    return Html::a('<i class="fa fa-image"></i>',$url,['title' => '图片', 'target'=>'_blank']);
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' =>'{view} {update}'
            ],
        ],
    ]); ?>
<?php Pjax::end(); ?></div>
